import {
    operator,
    model,
    factuerManage,
    region,
    equipType
} from '@/api/factuer';
import {
    tags
} from "@/api/system";
import {
    filterTreeData
} from "@/utils/index";
const mutations = {
    // 运营商
    SET_OPERATOR: (state, operator) => {
        state.operator = operator
    },
    //   设备型号
    SET_MODEL: (state, model) => {
        state.model = model
    },
    // 设备类型
    SET_EQUIP_TYPE: (state, equipType) => {
        state.equipType = equipType
    },
    //   厂商
    SET_FACTUER: (state, factuer) => {
        state.factuer = factuer
    },
    // 地区
    SET_REGION: (state, region) => {
        state.region = region
    },
    // 标签
    SET_TAGS: (state, tags) => {
        state.tags = tags
    },

}
const actions = {
    generatorOperator({
        commit
    }) {
        return new Promise((resolve, reject) => {
            operator('/all', 'get').then((response) => {
                const {
                    data
                } = response;
                commit('SET_OPERATOR', data);
                resolve(data)
            }).catch(error => {
                reject(error)
            })
        })
    },
    generatorModel({
        commit
    }) {
        return new Promise((resolve, reject) => {
            model('/datails', 'post').then((response) => {
                const {
                    data
                } = response;
                commit('SET_MODEL', data);
                resolve(data)
            }).catch(error => {
                reject(error)
            })
        })
    },
    generatorFactuer({
        commit
    }) {
        return new Promise((resolve, reject) => {
            factuerManage('/all', 'post').then((response) => {
                const {
                    data
                } = response;
                commit('SET_FACTUER', data);
                resolve(data)
            }).catch(error => {
                reject(error)
            })
        })
    },
    generatorRegion({
        commit
    }) {
        return new Promise((resolve, reject) => {
            region('/tree').then((response) => {
                const {
                    data
                } = response;
                let trees = filterTreeData(data);
                commit('SET_REGION', trees);
                resolve(trees)
            }).catch(error => {
                reject(error)
            })
        })
    },
    generatorEquipType({
        commit
    }) {
        return new Promise((resolve, reject) => {
            equipType('/datails', 'post').then((response) => {
                const {
                    data
                } = response;
                commit('SET_EQUIP_TYPE', data);
                resolve(data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    generatorTags({
        commit
    }) {
        return new Promise((resolve, reject) => {
            tags('/all', 'post').then((response) => {
                const {
                    data
                } = response;
                commit('SET_TAGS', data);
                resolve(data)
            }).catch(error => {
                reject(error)
            })
        })
    },
}
export default {
    namespaced: true,
    mutations,
    actions
}
